﻿using rmTest_EfIocAof.DBFirst;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace rmTest_EfIocAof
{
    public static class EfIocAopShow
    {
        public static void Show()
        {
            try
            {
                using (DBFirstContext dbContext = new DBFirstContext())
                {
                    dbContext.Database.Log += c => Console.WriteLine(c);
                    User user = dbContext.Users.Find(1);
                    var list = dbContext.Users.Where(x => x.Id > 1);
                    User userNew = new User()
                    {
                        Account = "admin",
                        State = 0,
                        CompanyId = 4,
                        CompanyName = "万达集团",
                        CreateTime = DateTime.Now,
                        CreatorId = 1,
                        Email = "110244@qq.com",
                        LastLoginTime = null,
                        LastModifierId = 0,
                        LastModifyTime = DateTime.Now,
                        Mobile = "212234234234",
                        Name = "yohoho",
                        Password = "123321123",
                        UserType = 1
                    };
                    dbContext.Users.Add(userNew);
                    //操作数据库时启动事务，可进行多表操作，天生防注入
                    dbContext.SaveChanges();

                    //更新操作
                    //userNew.Name = "安德鲁";
                    //dbContext.SaveChanges();

                    //删除数据
                    //dbContext.Users.Remove(userNew);
                    //dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {

                throw;
            }
            finally
            {
            }
        }
    }
}